<!DOCTYPE html>
<html>
<script src="../AmazeUI-2.4.2/assets/js/jquery.min.js"></script>
<script src="../AmazeUI-2.4.2/assets/js/amazeui.min.js"></script>
<script src="js/pluges/vue/dist/vue.js"></script>
<script src="js/pluges/axios/dist/axios.js"></script>
<script src="js/base/common.js"></script>
<head lang="en">
    <meta charset="UTF-8">
    <title>登录</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <meta name="format-detection" content="telephone=no">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp"/>

    <link rel="stylesheet" href="../AmazeUI-2.4.2/assets/css/amazeui.css"/>
    <link href="../css/dlstyle.css" rel="stylesheet" type="text/css">
</head>

<body>

<div class="login-boxtitle">
    <a href="home.html"><img alt="logo" src="../images/logobig.png"/></a>
</div>

<div class="login-banner" id="login">
    <div class="login-main">
        <div class="login-banner-bg"><span></span><img src="../images/big.jpg"/></div>
        <div class="login-box">

            <h3 class="title">登录商城</h3>

            <div class="clear"></div>

            <div class="login-form">
                <form>
                    <div class="user-name">
                        <label for="user"><i class="am-icon-user"></i></label>
                        <input type="text" v-model="phoneRegisterForm.phone" name="" id="user" placeholder="手机">
                    </div>
                    <div>
                        <input type="text" name="" v-model="phoneRegisterForm.imageCodeValue"
                               style="width: 180px;" placeholder="请输入图片验证码">
                        <img  @click="getImageCode" :src="imageCode"
                              class="captcha-image-temp" alt="点击换图" title="点击换图"
                              style="vertical-align: middle; cursor: pointer;">
                    </div>
                    <div class="verification">
                        <input type="tel" name="" style="width: 180px"
                               v-model="user.registerCode" placeholder="请输入验证码">
                        <button class="btn" @click="sendPhoneCode" type="button">获取
                        </button>
                    </div>
                </form>
            </div>

            <div class="login-links">
                <label for="remember-me"><input id="remember-me" type="checkbox">记住密码</label>
                <a href="#" class="am-fr">忘记密码</a>
                <a href="register.html" class="zcnext am-fr am-btn-default">注册</a>
                <br/>
            </div>
            <div class="am-cf">
                <input type="button" @click="goLogin" name="" value="登 录" class="am-btn am-btn-primary am-btn-sm">

            </div>
            <div class="am-cf">
                <input type="button" @click="gologinUser" name="" value="账 号 登 录" class="am-btn am-btn-primary am-btn-sm">
            </div>
            <div class="partner">
                <h3>合作账号</h3>
                <div class="am-btn-group">
                    <li><a href="#"><i class="am-icon-qq am-icon-sm"></i><span>QQ登录</span></a></li>
                    <li><a href="#"><i class="am-icon-weibo am-icon-sm"></i><span>微博登录</span> </a></li>
                    <li><a href="https://open.weixin.qq.com/connect/qrconnect?appid=wxd853562a0548a7d0&redirect_uri=http://bugtracker.itsource.cn/callback.html&response_type=code&scope=snsapi_login&state=9527#wechat_redirect"><i class="am-icon-weixin am-icon-sm"></i><span>微信登录</span> </a></li>
                </div>
            </div>

        </div>
    </div>
</div>


<div class="footer ">
    <div class="footer-hd ">
        <p>
            <a href="# ">恒望科技</a>
            <b>|</b>
            <a href="# ">商城首页</a>
            <b>|</b>
            <a href="# ">支付宝</a>
            <b>|</b>
            <a href="# ">物流</a>
        </p>
    </div>
    <div class="footer-bd ">
        <p>
            <a href="# ">关于恒望</a>
            <a href="# ">合作伙伴</a>
            <a href="# ">联系我们</a>
            <a href="# ">网站地图</a>
            <em>© 2015-2025 Hengwang.com 版权所有. 更多模板 <a href="http://www.cssmoban.com/" target="_blank"
                                                       title="模板之家">模板之家</a> - Collect from <a
                    href="http://www.cssmoban.com/" title="网页模板" target="_blank">网页模板</a></em>
        </p>
    </div>
</div>
</body>

<script type="text/javascript">
	new Vue({
		el:"#login",
		data:{
            imageCode:"",
            base64Prefix: "data:image/jpg;base64,",
            phoneRegisterForm:{
                phone:"",
                imageCodeValue: "",
                imageCode: "",
                type:"login"
            },
			user:{
                phone:"",
                registerCode:"",
				type:1
			}
		},
		methods:{
            // 1.生成UUID的方法
            createUuid() {
                var s = [];
                var hexDigits = "0123456789abcdefghi";
                for (var i = 0; i < 36; i++) {
                    s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
                }
                s[14] = "4"; // bits 12-15 of the time_hi_and_version field to 0010
                s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01
                s[8] = s[13] = s[18] = s[23] = "-";

                var uuid = s.join("");
                return uuid;
            },
            // 获取验证码的方法
            getImageCode() {
                // 查询localStroge中获取uuid
                var item = localStorage.getItem("registerImageCodeKey");
                // 判断localStroge中是否有key：registerImageCodeKey对应的值
                if (item == null || item === "") {
                    // 如果没有值 我们获取uuid
                    var s = this.createUuid();
                    // 将uuid保存到loacalStroage中
                    localStorage.setItem("registerImageCodeKey", s);
                }
                // 发送axios请求，传入uuid
                this.$http.get("/verifyCode/image/" + item).then(result => {
                    // 因为后端发送回来的是一个Base64编码的字符串（图片经过编码后形成的）所以我们需要拼接一个前缀才可以编译为图片，给图像验证码img标签的src赋值
                    this.imageCode = this.base64Prefix + result.data.result;
                })
            },
            sendPhoneCode(event){
                // 判断输入的电话号不能为空
                if (!this.phoneRegisterForm.phone) {
                    alert("电话号不能为空");
                    return;
                }
                // 判断输入的验证码不能为空
                if (!this.phoneRegisterForm.imageCodeValue) {
                    alert("验证码不能为空");
                    return;
                }
                // 判断输入的验证码长度是否为4
                if (this.phoneRegisterForm.imageCodeValue.length != 4) {
                    alert("请输入图片所示验证码");
                    return;
                }
                var sendButton = $(event.target);
                // 将按钮变成不可点击
                sendButton.attr("disabled", true);
                // 获取imageCode
                this.phoneRegisterForm.imageCode = localStorage.getItem("registerImageCodeKey");
                // 发送axios请求到后端
                this.$http.post("/verifyCode/smsCode", this.phoneRegisterForm)
                    .then(result => {
                        if (result.data.success) {
                            // 发起弹框
                            alert("手机验证码已经发送至您的手机，请注意查收");
                            // 设置60秒
                            var time = 60;
                            // 设置定时器
                            var Interval = window.setInterval(function () {
                                time = time - 1;
                                sendButton.html(time + "重新发送");
                                if (time <= 0) {
                                    sendButton.html("重新发送");
                                    // 将按钮变成可点击
                                    sendButton.attr("disabled", false);
                                    // 消除定时器
                                    window.clearInterval(Interval)
                                }

                            }, 1000)
                        } else {
                            alert("手机发送失败" + result.data.message);
                            // 将按钮变成可点击
                            sendButton.attr("disabled", false);
                        }
                    }).catch(result => {
                    alert("手机发送失败" + result.data.message);
                })
            },

            gologinUser(){
                location.href = "http://127.0.0.1/login.html";
            },
			goLogin(){
                this.user.phone = this.phoneRegisterForm.phone;
                // 发送axios请求
                this.$http.post("/login/phoneCode",this.user)
                    .then(result=>{
                        result = result.data;
                        if (result.success){
                            let token = result.result.token;
                            let logininfo = result.result.logininfo;
                            localStorage.removeItem("registerImageCodeKey");
                            localStorage.setItem("token",token);
                            localStorage.setItem("logininfo",JSON.stringify(logininfo));

                            location.href = "http://bugtracker.itsource.cn/index.html";
                        }else {
                            alert(result.message);
                        }
                    })
                    .catch(result=>{
                        alert("系统异常失败");
                    })
			}
		},
		mounted(){
            this.getImageCode();
		}
	})
</script>

</html>